import Vue from 'vue'
import Router from 'vue-router'
//  路由懒加载
const Login = () => import(/* webpackChunkName: "login_home_workhome" */ '../components/Login.vue')
// import Login from '../components/Login.vue'
const Home = () => import(/* webpackChunkName: "login_home_workhome" */ '../components/Home.vue')
// import Home from '../components/Home.vue'
const Workhome = () => import(/* webpackChunkName: "login_home_workhome" */ '../pages/Workhome.vue')
// import Workhome from '../pages/Workhome.vue'
const User = () => import(/* webpackChunkName: "user" */ '../pages/user/User.vue')
// import User from '../pages/user/User.vue'
const Power = () => import(/* webpackChunkName: "power_role" */ '../pages/power/Power.vue')
// import Power from '../pages/power/Power.vue'
const Role = () => import(/* webpackChunkName: "power_role" */ '../pages/power/Role.vue')
// import Role from '../pages/power/Role.vue'
const Product = () => import(/* webpackChunkName: "product_class_list_add" */ '../pages/product/Product.vue')
// import Product from '../pages/product/Product.vue'
const Class = () => import(/* webpackChunkName: "product_class_list_add" */ '../pages/product/Class.vue')
// import Class from '../pages/product/Class.vue'
const List = () => import(/* webpackChunkName: "product_class_list_add" */ '../pages/product/List.vue')
// import List from '../pages/product/List.vue'
const Add = () => import(/* webpackChunkName: "product_class_list_add" */ '../pages/product/Add.vue')
const Chart = () => import(/* webpackChunkName: "data" */ '../pages/data/Chart.vue')
// import Chart from '../pages/data/Chart.vue'
const OList = () => import(/* webpackChunkName: "ording" */ '../pages/ordering/OList.vue')
// import OList from '../pages/ordering/OList.vue'
// import Add from '../pages/product/Add.vue'
Vue.use(Router)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/workhome',
    meta: { name: '首页' },
    children: [
      { path: '/workhome', component: Workhome },
      { path: '/user', component: User, meta: { name: '用户列表' } },
      { path: '/power', component: Power, meta: { name: '角色列表' } },
      { path: '/character', component: Role, meta: { name: '权限列表' } },
      { path: '/productParam', component: Product, meta: { name: '商品列表' } },
      { path: '/classParam', component: Class, meta: { name: '分类参数' } },
      { path: '/product', component: List, meta: { name: '商品分类' } },
      { path: '/data', component: Chart, meta: { name: '数据统计' } },
      { path: '/ording', component: OList, meta: { name: '订单列表' } },
      { path: '/goods/add', component: Add }
    ]
  },
  {
    path: '/404',
    component: () => import('@/components/404')
  },
  { path: '*', redirect: '/404' }
]

const router = new Router({
  routes
})
//  路由拦截
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})
export default router
